# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libtommath
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=5
pkgdesc="Highly optimized and portable routines for integer based number theoretic applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://www.libtom.net/LibTomMath/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-libtool")
source=("https://github.com/libtom/libtommath/releases/download/v${pkgver}/ltm-${pkgver}.tar.xz"
        "0001-makefile-enable-no-undefined.patch")
sha256sums=('b7c75eecf680219484055fcedd686064409254ae44bc31a96c5032843c0e18b1'
            'b770559d51381e078bc84c9162fc711e0e3ebe17b94bc073c00ab5051cf85546')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-makefile-enable-no-undefined.patch"
}

build() {
  cp -rf "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  make -f makefile.shared \
    CC=${CC} PREFIX=${MINGW_PREFIX}
}

check() {
  cd ${srcdir}/build-${MSYSTEM}

  ./test.exe
}

package() {
  cd ${srcdir}/build-${MSYSTEM}

  make -f makefile.shared install \
    CC=${CC} PREFIX=${MINGW_PREFIX} DESTDIR=${pkgdir}

  install -Dm644 doc/bn.pdf "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/bn.pdf"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
